/**
 * Created by Jin on 2017/5/18.
 */
public class TestConsistent {

    public static ConsistentHash consistentHash;

    public static int[] conditions ;

    public static void main(String args[]) {

        consistentHash = ConsistentHash.getInstance();

        conditions = new int[consistentHash.servers.length];

        String[] nodes= new String[100];

        for (int i = 0; i < nodes.length; i++) {
            nodes[i] = String.valueOf(i);
        }
        for (int i = 0; i < nodes.length; i++) {
            String serverName = consistentHash.getServer(nodes[i]);
            calculatorResult(serverName);
            System.out.println("[" + nodes[i] + "]的hash值为" + consistentHash.getHash(nodes[i]) + ", 被路由到结点[" + serverName + "]");
        }

        for (int i = 0; i < conditions.length; i++) {
            System.out.println("[" + consistentHash.servers[i]+"]服务器映射的数量:"+conditions[i]);
        }

    }


    public static void calculatorResult(String name){

        for (int i = 0; i < consistentHash.servers.length; i++) {
            if (name.equals(consistentHash.servers[i])){
                conditions[i]++;
            }
        }

    }
}
